using UnityEngine;
using UnityEngine.UI;
using SgsUI;
using UnityEditor.UI;
using UnityEditor;
using System.Collections.Generic;
using System;

namespace SgsUI.Editor
{
    [CustomEditor(typeof(ButtonRes))]
    [CanEditMultipleObjects]

    public class ButtonResEditor : UnityEditor.Editor
    {
        private ButtonRes m_ButtonRes;

        private List<string> m_key_map = new List<string>
        {
            "target","m_type","res","buttonRes"
        };

        private Dictionary<string,SerializedProperty> m_prop = new Dictionary<string,SerializedProperty>();

        protected void OnEnable()
        {
            foreach(string key in m_key_map)
            {
                m_prop[key] = serializedObject.FindProperty(key);
            }

            m_ButtonRes = target as ButtonRes;
        }
        public override void OnInspectorGUI()
        {
            m_ButtonRes.UpdateButtonRes();

            serializedObject.ApplyModifiedProperties();
 
            serializedObject.Update();

            EditorGUILayout.PropertyField(m_prop["target"]);
            EditorGUILayout.PropertyField(m_prop["m_type"]);

            ButtonRes.Type typeEnum = (ButtonRes.Type)m_prop["m_type"].enumValueIndex;
            if(typeEnum == ButtonRes.Type.Simple_Btn)
            {
                EditorGUILayout.PropertyField(m_prop["res"]);
            }
            else if(typeEnum == ButtonRes.Type.Normal_Btn)
            {
                EditorGUILayout.PropertyField(m_prop["buttonRes"]);
            }

            serializedObject.ApplyModifiedProperties();
        }
    }
}